/* (C) Copyright 2008 Bill Buckels */

/* What Time is It - Apple Version by Bill Buckels */
/* plogo.c overlay module        */
/* this is a duplicate of flogo.c
   with the language variable set to 0 (english) */
/* this one uses auxmem (ems) routines and the upper ram bank   */
/* also restarts the program     */
/* june 1991                     */
/* the CINIT.OVR is called to set to graphics mode and */
/* load the font prior to this module being called.    */


/* for time.c */

#include <stdio.h>
#include <fcntl.h>
#include <prodos.h>
#include <sgtty.h>
#include <device.h>
#include <sysfunc.h>


extern char XPIC;
extern char YPIC;

char *pressmess[2]={"PRESS \"ESCAPE\" TO EXIT OR",
                    "APPUYEZ SUR \"ESC\" POUR QUITTER OU"};

char *pressmess2[2]={"ANY OTHER KEY TO CONTINUE",
                     "SUR UNE TOUCHE AUTRE POUR CONTINUER"};


int credits(language)
unsigned language;
{
  int temp, temp2, x;

  XPIC=0;
  YPIC=0;

  piclode("PLOGO.RAG");

  temp=20-(strlen(pressmess[language])/2);
  temp2=20-(strlen(pressmess2[language])/2);

  plots2(pressmess[language],temp,170,1);
  plots2(pressmess2[language],temp2,180,1);

  x = getch();

  plots2(pressmess[language],temp,170,0);
  plots2(pressmess2[language],temp2,180,0);


  return (x);
}


/* arguments of auxmem (ems) library name and image name */
/* uses plots2 for the message                  */

char *waitmess[2]={"ONE MOMENT PLEASE",
                   "UN MOMENT S.V.P."};

char *waitmess2[2]={"PRESS ANY KEY TO CONTINUE",
                    "APPUYEZ SUR UNE TOUCHE POUR CONTINUER"};



ovmain(progname,libname,libsize,language)
char *progname,*libname;
unsigned libsize,language;
{
  int c;
  int temp;
  char d;
  int emscheck();
  int emslode();

  char *KEYPRESS = (char*)0xC000;           /* return the last key press  */
  char *KEYCLEAR = (char*)0xC010;           /* clear the last key press   */

  language=0; /* hack */

  /* if the library is already in upper ram don't worry */
  if(emscheck(libname)==0)
  {

    /* if there is a problem don't continue */
    temp=20-(strlen(waitmess[language])/2);
    plots2(waitmess[language],temp,170,1);

    c=emslode(libname,libsize);

    plots2(waitmess[language],temp,170,0);

     if(c==-3||c==-1) {
		return 27;
	 }
   }
   else titleload(progname);

  temp=20-(strlen(waitmess2[language])/2);
  plots2(waitmess2[language],temp,170,1);
  c=getch();
  plots2(waitmess2[language],temp,170,0);

  c=credits(language);

  /* clean-up if we are leaving */
  if(c==27)
  {
      emsoff();
  }

  return(c);

}


/* open the program and display the embedded title */
/* upon re-entry */

titleload(progname)
char *progname;
{
    int fh;

    fh = open(progname,O_RDONLY,0xc3);
    lseek(fh,(long)0x2000,0);
    read(fh,(char *)0x4000,0x2000);
    close(fh);
    return 0;
}
